<?

//Data loading
$title='KAS - BON';
$title2='PEMBAYARAN UANG JALAN';
//if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
//else $perush = 'PT. MASAJI PRAYASA CARGO';

$perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = GridList ();
$pdf->GridTable($Result);
$pdf->Output();


function GridList () {
            $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
                    //$SQL = "SELECT * FROM ais_advance WHERE nobkt='".GetParam("nobkt","")."' ORDER BY urut";

                    $SQL = "SELECT * FROM ais_advance a
                            JOIN tbljoborder_costing_truck b ON a.jo_costing_truck_id = b.jo_costing_truck_id
                            JOIN tblactivity_nr c ON b.activities_id = c.act_nr_id
                            JOIN tbljoborder d ON b.jo_id = d.jo_id
                            JOIN tblproject e ON d.project_id = e.project_id
                            JOIN tbldebtur g ON d.debtur = g.CUCODE
                            WHERE a.nobkt='".GetParam("nobkt","")."' ORDER BY urut limit 1";
                            //echo"$SQL"; exit;


                    return $DBConnection->dbc->get_results($SQL,ARRAY_A);
}

function ReadHeader($nobkt) {
  global $DBConnection;
  $SQL = "SELECT *,DATE_FORMAT(tglbkt,'%d %M, %Y') as spell_date  FROM ais_advance WHERE nobkt='$nobkt' LIMIT 1";
  return $DBConnection->dbc->get_row($SQL);
}


class PDFReport extends PDF {

    function Header() {
        global $title,$title2,$perush,$page,$DEFINE_FONT, $DBConnection;
        if ($DEFINE_FONT==0) {
            $this->AddFont('Arial','','arialn.php');
            $DEFINE_FONT=1;
        }
                $Field = ReadHeader(GetParam("nobkt",""));
                $this->spell_date = strtoupper($Field->spell_date);
                list($this->year,$this->month,$this->day) = explode("-",$Field->tglbkt);

           
                $this->SetFont('Arial','',10);
                $this->Cell(50,1,"",0,0,'L',0);
                $this->Ln();
                $this->SetLeftMargin(5);
                $this->Cell(50,1,"",0,0,'L',0);
                $this->Ln();
                $this->Cell(50,5,$perush,0,0,'C',0);
                $this->Cell(155,5,GetParam("nobkt",""),0,0,'R',0);
                $this->Ln();
                $this->Cell(50,5,"JAKARTA",0,0,'C',0);
                $this->Ln();
                $this->SetFont('Arial','',16);
               
                $this->Cell(205,7,$title2,0,1,'C',0);
                $this->SetFont('Arial','',10);
                $this->SetLeftMargin(15);
                $this->Ln();
                
                

       
            $SQLCurr = "SELECT DISTINCT curr as job_costing_curr FROM ais_advance a
                        WHERE nobkt='".GetParam("nobkt","")."' ORDER BY urut";

            $Curr = $DBConnection->dbc->get_var($SQLCurr);


            $w=array(15,140,50);
            $this->SetFont('Arial','',11);
            $this->Cell(100,7,"NO BUKTI: ".GetParam("nobkt",""),0,0,'L',0);
            $this->Cell(100,7,"TANGGAL: ".$this->day."/".$this->month."/".$this->year,0,0,'L',0);
            $this->Ln();
            
    }

    function GridTable($MyResult) {
        //Column widths
        
        //echo "<pre>";
        //print_r($MyResult);
        
        global $DBConnection;
        $w=array(15,140,50);
        //Data
        if ($MyResult)
        {         
			foreach($MyResult as $row)
			{
		   
				$this->Cell(200,7,"JENIS ALAT : ".$row['truck_mark'],0,0,'L',0);
				$this->Ln();
				$this->Cell(100,7,"PROYEK: ".$row['project_name'],0,0,'L',0);
				$this->Ln();
				$this->Cell(100,7,"KAPAL: ".$row['vessel'],0,0,'L',0);
				$this->Ln();
				$this->Cell(100,7,"TRAYEK: ".$row['trayek'],0,0,'L',0);
				$this->Ln();
				$this->Cell(100,7,"CARGO: MATERIAL PROYEK",0,0,'L',0);
				$this->Ln();
				
				
				

				
			}
		 }	
            
		

		
		$this->Ln();
		$this->Ln();

		$GetPerson = $DBConnection->dbc->get_row("SELECT * FROM tblprofile", ARRAY_A);
		//return $DBConnection->dbc->get_row($SQL);

		$this->Cell(60,5,"Setuju Bayar",1,0,'C',0);
		$this->Cell(60,5,"Penanggung Jawab",1,0,'C',0);
		$this->Cell(60,5,"Penerima",1,0,'C',0);
		$this->Ln();
		$this->Cell(10,5,"Tgl.",1,0,'C',0);
		$this->Cell(50,5,"",1,0,'C',0);
		$this->Cell(10,5,"Tgl.",1,0,'C',0);
		$this->Cell(50,5,"",1,0,'C',0);
		$this->Cell(10,5,"Tgl.",1,0,'C',0);
		$this->Cell(50,5,"",1,0,'C',0);
		$this->Ln();
		$this->Cell(10,5,"Nama",1,0,'C',0);
		$this->Cell(50,5,$GetPerson["ttdbs1"],1,0,'C',0);
		$this->Cell(10,5,"Nama",1,0,'C',0);
		$this->Cell(50,5,$GetPerson["ttdbs2"],1,0,'C',0);
		$this->Cell(10,5,"Nama",1,0,'C',0);
		$this->Cell(50,5,$row["debnam"],1,0,'C',0);
		$this->Ln();
		$this->Cell(10,8,"Ttd",1,0,'C',0);
		$this->Cell(50,8,"",1,0,'C',0);
		$this->Cell(10,8,"Ttd",1,0,'C',0);
		$this->Cell(50,8,"",1,0,'C',0);
		$this->Cell(10,8,"Ttd",1,0,'C',0);
		$this->Cell(50,8,"",1,0,'C',0);



        //Closure line
    }

    function Footer() {
        //Closure line
        //$this->Cell(205,0,'','T');
    }

}


?>
